369A - Valera and Plates - CodeForces Solution


greedy implementation *900

Please click on ads to support us..

Python Code:

inp = list(map(int, input().split()))
numofdays = inp[0]
numofdeeplates = inp[1]
numofplates = inp[2]

inp2 = list(map(int, input().split()))

numofcleans = 0

for i in range(0, numofdays):
	if inp2[i] == 1:
		if numofdeeplates > 0:
			numofdeeplates -= 1
		else:
			numofcleans += 1
	else: 
		if numofplates > 0:
			numofplates -= 1
		else: 
			if numofdeeplates > 0:
				numofdeeplates -= 1
			else:
				numofcleans += 1
				
print(numofcleans)
	

C++ Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   
    int n,bowl,plate;
    cin>>n>>bowl>>plate;

    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];

    int cnt_1=0,cnt_2=0,remain_1st_dish=0,remain_2nd_dish=0;
    for(int i=0; i<n; i++)
    {
        if(a[i]==1)
            cnt_1++;
        else cnt_2++;
    }

    //cout<<"cnt_1 = "<<cnt_1<<"\ncnt_2 = "<<cnt_2<<"\n";
    if(bowl<=cnt_1)
    {
        remain_1st_dish=cnt_1-bowl;
        //cnt_1=remain_1st_dish;
        cnt_1-=bowl;
        bowl=0;
    }
    else
    {
        remain_1st_dish=0;
        bowl-=cnt_1;
        cnt_1=0;
    }

    // cout<<"\n\nremain_1st_dish = "<<remain_1st_dish<<"\n";
    // cout<<"plate = "<<plate<<"\n";
    // cout<<"cnt_1 = "<<cnt_1<<"\n";
    // cout<<"cnt2 = "<<cnt_2<<"\n";
    // cout<<"bowl = "<<bowl<<"\n\n\n";


    if(plate<=cnt_2)
    {
        remain_2nd_dish=cnt_2-plate;
        cnt_2-=plate;
        plate=0;
    }
    else
    {
        remain_2nd_dish=0;

        plate=plate-cnt_2;
        cnt_2=0;
    }
    //cout<<"\n\nremain_2nd_dish = "<<remain_2nd_dish<<"\n";
    //cout<<"plate = "<<plate<<"\n";
    //cout<<"cnt2 = "<<cnt_2<<"\n";
    // cout<<"bowl = "<<bowl<<"\n\n\n";


    if(cnt_2>0 && bowl>0)
    {
        if(cnt_2>=bowl)
        {
            remain_2nd_dish=cnt_2-bowl;

            cnt_2-=bowl;
            bowl=0;
        }
        else
        {
            remain_2nd_dish=0;

            bowl=bowl-cnt_2;
            cnt_2=0;

        }
    }
    //cout<<".remain_1st_dish = "<<remain_1st_dish<<"\n";
    //cout<<".remain_2nd_dish = "<<remain_2nd_dish<<"\n";
    //cout<<"plate = "<<plate<<"\n";


    // int ans=0;
    //int x=remain_1st_dish+remain_1st_dish;
    //if(x==0)
    //    ans=0;
    //else ans=n-x;

    //if(ans<=0)
    //  cout<<0;
    //  else cout<<ans;
    cout<<remain_1st_dish+remain_2nd_dish;

}


Comments

Submit
0 Comments
More Questions

48A - Rock-paper-scissors
294A - Shaass and Oskols
1213A - Chips Moving
490A - Team Olympiad
233A - Perfect Permutation
1360A - Minimal Square
467A - George and Accommodation
893C - Rumor
227B - Effective Approach
1534B - Histogram Ugliness
1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General
1106A - Lunar New Year and Cross Counting
58A - Chat room
230A - Dragons
200B - Drinks
13A - Numbers
129A - Cookies
1367B - Even Array
136A - Presents
1450A - Avoid Trygub
327A - Flipping Game
411A - Password Check
1520C - Not Adjacent Matrix